package com.watering.plan;

import android.app.Activity;
import android.os.Bundle;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.SystemClock;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

import com.watering.plan.NotificationService;

public class MainNotifier extends Activity{
        
        private PendingIntent mAlarmSender;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            
           PendingIntent mAlarmSender = PendingIntent.getService(MainNotifier.this,
                    0, new Intent(MainNotifier.this, NotificationService.class), 0);
            long firstTime = SystemClock.elapsedRealtime();
            
            AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
        //      am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
        //                      firstTime, 30*1000, mAlarmSender);
            
        }
        
        public void doIt(){
       // 	mAlarmSender = PendingIntent.getService(this,
       //             0, new Intent(this, NotificationService.class), 0);
        	long firstTime = SystemClock.elapsedRealtime();

         //   AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
          //  am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
          //                  firstTime, 30*1000, mAlarmSender);

            Toast.makeText(MainNotifier.this, R.string.repeating_scheduled,
                    Toast.LENGTH_LONG).show();
        }
        
        public void stopIt(){
        	 // And cancel the alarm.
            AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
            am.cancel(mAlarmSender);

            // Tell the user about what we did.
            Toast.makeText(MainNotifier.this, R.string.repeating_unscheduled,
                    Toast.LENGTH_LONG).show();
        }
  /*      
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        mAlarmSender = PendingIntent.getService(MainNotifier.this,
                0, new Intent(MainNotifier.this, NotificationService.class), 0);
        
        setContentView(R.layout.main);
        
       // Button button = (Button)findViewById(R.id.start_notifications);
     //   button.setOnClickListener(mStartListener);
     //   button = (Button)findViewById(R.id.stop_notifications);
     //   button.setOnClickListener(mStopListener);
    }
    
    private OnClickListener mStartListener = new OnClickListener() { 
         public void onClick(View v) {
                 
             long firstTime = SystemClock.elapsedRealtime();

             AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
             am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                             firstTime, 30*1000, mAlarmSender);

             Toast.makeText(MainNotifier.this, R.string.repeating_scheduled,
                     Toast.LENGTH_LONG).show();
         }
    };
    
    private OnClickListener mStopListener = new OnClickListener() {
        public void onClick(View v) {
            // And cancel the alarm.
            AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
            am.cancel(mAlarmSender);

            // Tell the user about what we did.
            Toast.makeText(MainNotifier.this, R.string.repeating_unscheduled,
                    Toast.LENGTH_LONG).show();

        }
    };
    */
}